package gui;

import manager.Manager;
import world.*;

public class ObjDataWindow extends javax.swing.JFrame 
{
    //The entity being displayed.
    Entity subject;

    public ObjDataWindow() {
        initComponents();
    }
    /**
     * Opens file chooser. Selected file will be saved to. Saved file 
     * will be a flat file version of the selected agent's behavior. 
     * Visible only when entity is an animal.
     */
    void exportEntity()
    {
        
    }
    
    /**
     * Argument:
     * -Animal to view
     * -Reference back to manager
     * Assigns argument to subject. Sets visibility of all animal specific 
     * labels to true, calls getSpecies() in manager passing the animal’s 
     * species attribute. Uses result and animal’s data to show 
     * current/max stats of animal being displayed.
     */
    void setEntity(Animal a, Manager m)
    {
        subject = a;
        lblAction.setVisible(true);
        lblGeneration.setVisible(true);
        //lblHealth.setVisible(true);
        lblHunger.setVisible(true);
        lblPregnancy.setVisible(true);
        lblTarget.setVisible(true);
        
        Species s = m.getSpecies(a.getSpecies());
        
        if (a.getAction() == World.ATTACK)
        {
            lblAction.setText("Action: attack");
        }
        else if(a.getAction() == World.EAT)
        {
            lblAction.setText("Action: eat");
        }
        else if(a.getAction() == World.MATE)
        {
            lblAction.setText("Action: mate");
        }
        else if(a.getAction() == World.MOVE)
        {
            lblAction.setText("Action: move");
        }
        else if(a.getAction() == World.WAIT)
        {
            lblAction.setText("Action: wait");
        }
        lblGeneration.setText("Generation: " + a.getGeneration());
        lblEntityType.setText("Animal of species" + s.getName());
        //lblHealth.setText("Health: " + a.getLife() + "/" + s.getMaxLife());
        lblHunger.setText("Hunger: " + a.getHunger() + "/" + s.getMaxHunger());
        lblAlt.setText("Health: " + a.getLife() + "/" + s.getMaxLife());
        lblLocX.setText("X: " + a.getX());
        lblLocY.setText("Y: " + a.getY());
        if (a.getPregnancy() < 0)
        {
            lblPregnancy.setText("Animal is not pregnant");
        }
        else if (a.getPregnancy() == 0)
        {
            lblPregnancy.setText("Animal gives birth next turn");
        }
        else
        {
            lblPregnancy.setText("Animal gives birth in " + a.getPregnancy() + " turns");
        }
        //lblTarget.setText(m.g);
    }
    
    /**
     * Argument:
     * -edible to view
     * -Reference back to manager
     * Assigns argument to subject. Sets visibility of all animal 
     * specific labels to false, displays data about subject on 
     * remaining visible labels.
     */
    void setEntity(Edible e, Manager m)
    {
        subject = e;
        lblAction.setVisible(false);
        lblGeneration.setVisible(false);
        //lblHealth.setVisible(true);
        lblHunger.setVisible(false);
        lblPregnancy.setVisible(false);
        lblTarget.setVisible(false);
        
        //Species s = m.getSpecies(a.getSpecies());
        
        //lblGeneration.setText("Generation: " + a.getGeneration());
        if (e.getType() == Edible.MEAT)
        {
            lblEntityType.setText("Meat");
        }
        else
        {
            lblEntityType.setText("Vegetable");
        }
        //lblHealth.setText("Health: " + a.getLife() + "/" + s.getMaxLife());
        //lblHunger.setText("Hunger: " + a.getHunger() + "/" + s.getMaxHunger());
        lblAlt.setText("Remaining food: " + e.getFood());
        lblLocX.setText("X: " + e.getX());
        lblLocY.setText("Y: " + e.getY());
//        if (a.getPregnancy() < 0)
//        {
//            lblPregnancy.setText("Animal is not pregnant");
//        }
//        else if (a.getPregnancy() == 0)
//        {
//            lblPregnancy.setText("Animal gives birth next turn");
//        }
//        else
//        {
//            lblPregnancy.setText("Animal gives birth in " + a.getPregnancy() + " turns");
//        }
    }
    
    /**
     * Calls setEntity and passes subject.
     */
    void update()
    {
        //setEntity(subject, );
    }
    


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        lblEntityType = new javax.swing.JLabel();
        lblLocX = new javax.swing.JLabel();
        lblLocY = new javax.swing.JLabel();
        lblAlt = new javax.swing.JLabel();
        lblAction = new javax.swing.JLabel();
        lblTarget = new javax.swing.JLabel();
        lblHunger = new javax.swing.JLabel();
        lblPregnancy = new javax.swing.JLabel();
        lblGeneration = new javax.swing.JLabel();
        pnlEntityColor = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridBagLayout());

        lblEntityType.setText("Entity type");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(lblEntityType, gridBagConstraints);

        lblLocX.setText("X Axis Location: 0");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        getContentPane().add(lblLocX, gridBagConstraints);

        lblLocY.setText("Y Axis Location: 0");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        getContentPane().add(lblLocY, gridBagConstraints);

        lblAlt.setText("jLabel1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        getContentPane().add(lblAlt, gridBagConstraints);

        lblAction.setText("jLabel1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        getContentPane().add(lblAction, gridBagConstraints);

        lblTarget.setText("jLabel1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        getContentPane().add(lblTarget, gridBagConstraints);

        lblHunger.setText("jLabel1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 7;
        getContentPane().add(lblHunger, gridBagConstraints);

        lblPregnancy.setText("jLabel1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 8;
        getContentPane().add(lblPregnancy, gridBagConstraints);

        lblGeneration.setText("jLabel1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 9;
        getContentPane().add(lblGeneration, gridBagConstraints);

        pnlEntityColor.setBackground(new java.awt.Color(51, 255, 51));
        pnlEntityColor.setPreferredSize(new java.awt.Dimension(25, 25));

        javax.swing.GroupLayout pnlEntityColorLayout = new javax.swing.GroupLayout(pnlEntityColor);
        pnlEntityColor.setLayout(pnlEntityColorLayout);
        pnlEntityColorLayout.setHorizontalGroup(
            pnlEntityColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 25, Short.MAX_VALUE)
        );
        pnlEntityColorLayout.setVerticalGroup(
            pnlEntityColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 25, Short.MAX_VALUE)
        );

        getContentPane().add(pnlEntityColor, new java.awt.GridBagConstraints());

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel lblAction;
    private javax.swing.JLabel lblAlt;
    private javax.swing.JLabel lblEntityType;
    private javax.swing.JLabel lblGeneration;
    private javax.swing.JLabel lblHunger;
    private javax.swing.JLabel lblLocX;
    private javax.swing.JLabel lblLocY;
    private javax.swing.JLabel lblPregnancy;
    private javax.swing.JLabel lblTarget;
    private javax.swing.JPanel pnlEntityColor;
    // End of variables declaration//GEN-END:variables
}
